/******************************************************************************
*
* Copyright (C), 2013, mophie. Co., Ltd. All Rights Reserved. 
*
* Version: v1.0.0
* $$Datae: 2013-7-5  
*
* Description:    
*   IIC Function
*
* Function List: 
* 
* History:        
*         1. $$data:  2013-7-5
*            Author:  JPM team         
*
******************************************************************************/
#ifndef _twi_api_h
#define _twi_api_h

/***Include file list*********************************************************/
#include "twi.h"

/********typedef**************************************************************/
typedef struct _twi_transfer_arg {
	// TWI address/commands to issue to the other chip (node).
	uint8_t inter_addr[3];
	// Length of the TWI data address segment (1-3 bytes).
	uint32_t inter_addr_length;
	//! Where to find the data to be transferred.
	void *buffer;
	// How many bytes do we want to transfer.
	uint32_t transfer_length;
	// TWI chip address to communicate with.
	uint8_t deveic_addr;
} twi_transfer_arg;

/********MARC define**********************************************************/
#define TWI0_PORT                PIOA
#define TWI0_TWD_PIN_NUM         17
#define TWI0_TWCK_PIN_NUM        18

#define TWI1_PORT                PIOB
#define TWI1_TWD_PIN_NUM         12
#define TWI1_TWCK_PIN_NUM        13

/********function list********************************************************/
void TWI_init(Twi *p_twi, uint32_t cpu_hz);
uint32_t TWI_master_write(Twi *p_twi, twi_transfer_arg *p_transfer_arg);
uint32_t TWI_master_read(Twi *p_twi, twi_transfer_arg *p_transfer_arg);

#endif
